package com.gmu.service.impl;

import com.gmu.domain.ResResult;
import com.gmu.mapper.TblUnitsMapper;
import com.gmu.pojo.Page;
import com.gmu.pojo.TblSampleAddress;
import com.gmu.mapper.TblSampleAddressMapper;
import com.gmu.pojo.TblUnits;
import com.gmu.service.TblSampleAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gmu.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 采样地点表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-07-24
 */
@Service
public class TblSampleAddressServiceImpl extends ServiceImpl<TblSampleAddressMapper, TblSampleAddress> implements TblSampleAddressService {

    @Autowired
    private TblUnitsMapper tblUnitsMapper;

    @Autowired
    private TblSampleAddressMapper tblSampleAddressMapper;

    @Override
    public ResResult<?> getAllSampleAddressByUnitsId(Integer unitsId, Page page) {

        Integer startIndex = PageUtil.getStartIndex(page);
        Integer pageSize = PageUtil.getPageSize(page);
        List<TblSampleAddress> tblSampleAddresses = tblSampleAddressMapper.getAllSampleAddressByUnitsId(startIndex,pageSize,unitsId);
        Integer total = tblSampleAddressMapper.getAllSampleAddressByUnitsIdTotal(startIndex,pageSize,unitsId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("tblSampleAddresses",tblSampleAddresses);

        return new ResResult<>(200,map);
    }
}
